﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Game.Kernel;
using Game.Entity.Accounts;
using Game.Entity.Treasure;
using Game.Facade;
using Game.Utils;
using System.Text;

namespace Game.Web.UserService
{
    public partial class InsureTransferRecord : System.Web.UI.Page
    {
        public int LUserID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            //判断是否登录
            if(!Fetch.IsUserOnline())
            {
                return;
            }
            LUserID = Fetch.GetUserCookie().UserID;

            if (!IsPostBack)
            {
                DataBindInsure();
            }
        }

        /// <summary>
        /// 绑定查询数据
        /// </summary>
        private void DataBindInsure()
        {
            StringBuilder sWhere = new StringBuilder();

            SystemStatusInfo status = FacadeManage.aideAccountsFacade.GetSystemStatusInfo(AppConfig.SystemConfigKey.TransferStauts.ToString());
            AccountsAgent agent = FacadeManage.aideAccountsFacade.GetAccountAgentByUserID(LUserID);
            if(status != null && status.StatusValue == 1 && (agent.AgentID ==0 || agent.Nullity == 1))
            {
                sWhere.AppendFormat(" WHERE (SourceUserID = {0} OR TargetUserID = {0}) AND TradeType!=3", LUserID);
            }
            else
            {
                sWhere.AppendFormat(" WHERE SourceUserID = {0} OR TargetUserID = {0}", LUserID);
            }

            int sPageIndex = GameRequest.GetQueryInt("page", 1);
            int sPageSize = anpPage.PageSize;

            PagerSet pagerSet = FacadeManage.aideTreasureFacade.GetInsureTradeRecord(sWhere.ToString(), sPageIndex, sPageSize);
            anpPage.RecordCount = pagerSet.RecordCount;

            if (pagerSet.PageSet.Tables[0].Rows.Count > 0)
            {
                rptInsureList.DataSource = pagerSet.PageSet;
                rptInsureList.DataBind();

                this.rptInsureList.Visible = true;
                this.litNoData.Visible = false;
            }
            else
            {
                this.rptInsureList.Visible = false;
                this.litNoData.Visible = true;
            }
        }

        /// <summary>
        /// 根据用户ID获取ID
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        public string GetGameIDByUserID(int userID)
        {
            int gameID = FacadeManage.aideAccountsFacade.GetGameIDByUserID(userID);
            return gameID == 0 ? "" : gameID.ToString();
        }
    }
}